# -*- coding:utf-8 -*-
import requests
import json
from django.test import TestCase, Client
from django.http import HttpRequest
from apps.api import tasks

# Create your tests here.
# class titlePageTest(TestCase):
#    def test_loginpage_returns_title_html(self):
#        request = HttpRequest()
#        response = login(request)
#        self.assertIn(b'<title>AutotestPlat</title>', response.content)


class requestTest(TestCase):
    def setUp(self):
        self.url="http://47.110.50.181/article/list/"
        self.headers= {
                'Host': 'HOSTNAME',
                'Connection': 'keep-alive',
                'CredentialId': id,
                'Content-Type': 'application/json'
            }

    def test_POST(self):
        res=requests.get(self.url,params={'a':'b'})
        result=res.json()
        res_dic=json.loads(result)

        self.assertEqual(res.status_code , 200)
        self.assertEqual(res_dic['status'] , False)
        self.assertEqual(res_dic['result'] ,"sucess")

class contentTest(TestCase):
    def setUp(self):
        print("单元测试启动！")
    def test_seturl_null(self):
        """
        输入参数为空时
        """
        url=""
        urlset = tasks.seturl(url)
        self.assertEqual(urlset,"127.0.0.1")
        # self.asserTrue()
    def test_seturl_noone(self):
        """
        输入参数为空时
        """
        url="111"
        urlset = tasks.seturl(url)
        self.assertEqual(urlset,"127.0.0.1")
        # self.asserTrue()
    def test_seturl_sucess(self):
            """
            输入参数为空时
            """
            url="HOSTNAME"
            urlset = tasks.seturl(url)
            self.assertEqual(urlset,"47.110.50.181")
            # self.asserTrue()
        




# if __name__ == '__main__':
#     django.test.main()